package com.smart.home.mapper;

import com.smart.home.annotation.autoFill;
import com.smart.home.entity.Users;
import com.smart.home.enumeration.OperationType;
import com.smart.home.vo.UserVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {



    /**
     * 通过用户名查询用户
     *
     * @param username
     * @param username
     * @return Users
     */
    @Select("select * from smarthome.users where username = #{username}")
    Users SelectByUsername(String username);

    /**
     * 插入用户
     * @param users
     * @param users
     * @return Integer
     */
    @autoFill(value = OperationType.INSERT)
    Integer insert(Users users);

    @Select("select username from smarthome.users where username = #{username}")
    String SelectByUsername1(String username);

    @Select("select email from smarthome.users where email = #{email}")
    String SelectByEmail1(String email);

    /**
     * 查询密码
     * @param userId
     * @return
     */
    @Select("select password from smarthome.users where id = #{userId}")
    String QueryPasswordById(Long userId);

    @Update("update smarthome.users set password = #{newPassword} where id = #{userId}")
    void UpdatePassword(String newPassword, Long userId);

    @Select("select id,uuid,status,created_at,updated_at,username,email,phone from smarthome.users where id = #{id}")
    UserVO selectUserInfo(Long id);
}
